package com.ruyuan.little.project.rocketmq.api.login.controller;

import com.alibaba.fastjson.JSON;
import com.ruyuan.little.project.common.dto.CommonResponse;
import com.ruyuan.little.project.rocketmq.api.login.dto.LoginRequestDTO;
import com.ruyuan.little.project.rocketmq.api.login.service.LoginService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author Bryce
 * @create 2021-04-21 22:54
 * @Description
 */
@RestController
@RequestMapping("/api/login")
public class LoginController {

    private static final Logger LOGGER = LoggerFactory.getLogger(LoginController.class);

    /**
     * 登陆接口
     */
    @Resource
    private LoginService loginService;

    /**
     * 登陆请求
     *
     * @param loginRequestDTO 登陆请求信息
     * @return 结果
     */
    public CommonResponse wxLogin(@RequestBody LoginRequestDTO loginRequestDTO){
        // TODO 模拟接收到用户登陆请求
        LOGGER.info("login success user info:{}", JSON.toJSONString(loginRequestDTO));

        // 第一次登陆下发优惠券
        loginService.firstLoginDistributeCoupon(loginRequestDTO);

        return CommonResponse.success();
    }

    /**
     * 重置登陆状态 TODO 方便测试使用
     * @param phoneNumber 用户手机号
     * @return 结果
     */
    public CommonResponse resetFirstLoginStatus(@RequestParam(value = "phoneNumber") String phoneNumber){
        LOGGER.info("rest user first login status phoneNumber:{}",phoneNumber);
        loginService.resetFirstLoginStatus(phoneNumber);
        return CommonResponse.success();

    }
}
